import re

with open('/home/llm_user/index/meta-learning/stable_meta_learning/PEARL_SAC2.out','r',encoding='utf-8') as f:
    data = f.read()
    actor_loss = re.findall(r'actor_loss.*?\|(.*?)\|',data)
    critic_loss = re.findall(r'critic_loss.*?\|(.*?)\|',data)
    success_rate = re.findall(r'success_rate.*?\|(.*?)\|',data)

    actor_loss = [float(loss.strip()) for loss in actor_loss]
    critic_loss = [float(loss.strip()) for loss in critic_loss]
    success_rate = [float(rate.strip()) for rate in success_rate]


import matplotlib.pyplot as plt
import numpy as np

# Data for plotting
t = np.arange(0, len(success_rate)) * 4
actor_loss = np.array(actor_loss)
critic_loss = np.array(critic_loss)

title = 'success_rate'

fig, ax = plt.subplots()
ax.plot(t, eval(title))

ax.set(xlabel='episodes', ylabel=f'{title}',
       title=f'{title}')

ax.grid()

fig.savefig(f"{title}.png")
plt.show()